
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using Andromeda.Global.Business;
using Andromeda.Global.Data.Db;
using Andromeda.Global.Common;
using ForgeIt.Dal.dbo.Validator;

  
namespace ForgeIt.Dal.dbo.Stub
{
	internal abstract class DBAppUserStub : dboSchema
	{
		#region private fields

		/// <summary>
		/// (fieldname, datatype, ischangeable(!isidentity), isinsertable(!isidentity), isforeignkey, foreigntable
		/// </summary>

		protected readonly DbField foIdAppUser = new DbField("IdAppUser", DbType.Int32, true, true, false, false, false, "");

		protected readonly DbField foIdEntity = new DbField("IdEntity", DbType.Int32, false, false, true, true, true, "Entity");

		protected readonly DbField foIdApplication = new DbField("IdApplication", DbType.Int32, false, false, true, true, true, "Application");

		protected readonly DbField foUsername = new DbField("Username", DbType.String, false, false, true, true, false, "");

		protected readonly DbField foPwd = new DbField("Pwd", DbType.String, false, false, true, true, false, "");

  
        #region local cache - Foreign Keys

        protected DBEntity localIdEntity;
  

        protected DBApplication localIdApplication;
  

        #endregion local cache - Foreign Keys


        #endregion private fields

        #region constructors

        protected DBAppUserStub()
		{
		}

		protected DBAppUserStub(bool ignorethis, string foUsername, string foPwd, Int32 foIdEntity, Int32 foIdApplication)
		{

			this.foUsername.Value = foUsername;

			this.foPwd.Value = foPwd;

			this.foIdEntity.Value = foIdEntity;

			this.foIdApplication.Value = foIdApplication;

		}
	
		#endregion constructors
    
		#region public properties
		
		public override DbConnector CleanEntity
		{
			get { return new DBAppUser(); }
		}


		public int IdAppUser
		{
			get { return ObjectConverter.ToInt32(foIdAppUser.Value); }
		}

		public int IdEntity
		{
			get { return ObjectConverter.ToInt32(foIdEntity.Value); }
			set { foIdEntity.Value = value; }
		}

		public int IdApplication
		{
			get { return ObjectConverter.ToInt32(foIdApplication.Value); }
			set { foIdApplication.Value = value; }
		}

		public string Username
		{
			get { return ObjectConverter.ToString(foUsername.Value); }
			set { foUsername.Value = value; }
		}

		public string Pwd
		{
			get { return ObjectConverter.ToString(foPwd.Value); }
			set { foPwd.Value = value; }
		}

  
		public override string TableName
		{
			get { return "AppUser"; }
		}



        #region Foreign Keys
      
        /// <summary>
        /// Getter method for Object encapsulated view of foreign key
        /// </summary>
        public virtual DBEntity GetFK_IdEntity()
        {
          return localIdEntity ?? (localIdEntity = DBEntity.GetEntity(IdEntity));
        }
        /// <summary>
        /// Setter method for Object encapsulated view of foreign key
        /// </summary>        
        public virtual void SetFK_IdEntity(DBEntity paramIdEntity)
        {
          localIdEntity = paramIdEntity;
          IdEntity = paramIdEntity.IdEntity;
        }
      
        /// <summary>
        /// Getter method for Object encapsulated view of foreign key
        /// </summary>
        public virtual DBApplication GetFK_IdApplication()
        {
          return localIdApplication ?? (localIdApplication = DBApplication.GetEntity(IdApplication));
        }
        /// <summary>
        /// Setter method for Object encapsulated view of foreign key
        /// </summary>        
        public virtual void SetFK_IdApplication(DBApplication paramIdApplication)
        {
          localIdApplication = paramIdApplication;
          IdApplication = paramIdApplication.IdApplication;
        }
      
        #endregion Foreign Keys


		    protected override ValidationModelBase Validator
		    {
			    get { return new DBAppUserValidator(); }
		    }
		#endregion public properties
    
		#region enumerator

		/// <summary>
		/// This enumerator contains a list of all the fields of the datasource
		/// </summary>
		public enum FieldNames
		{
			IdAppUser,
			IdEntity,
			IdApplication,
			Username,
			Pwd,

		}

		#endregion enumerator
    
		#region generic field methods

		/// <summary>
		/// Validates if a given  field value is a DbNull
		/// </summary>
		/// <param name="fieldName">The field to validate</param>
		///<returns>true if is DbNull, false otherwise</returns>
		public bool IsDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdAppUser: return (foIdAppUser.Value is DBNull);

				case FieldNames.IdEntity: return (foIdEntity.Value is DBNull);

				case FieldNames.IdApplication: return (foIdApplication.Value is DBNull);

				case FieldNames.Username: return (foUsername.Value is DBNull);

				case FieldNames.Pwd: return (foPwd.Value is DBNull);

			}

			throw new InvalidDataException();
		}

		/// <summary>
		/// Sets the given field value to DbNull
		/// </summary>
		/// <param name="fieldName">The field to set</param>
		public void SetDbNull(FieldNames fieldName)
		{
			switch (fieldName)
			{

				case FieldNames.IdAppUser:
					foIdAppUser.Value = DBNull.Value; break;

				case FieldNames.IdEntity:
					foIdEntity.Value = DBNull.Value; break;

				case FieldNames.IdApplication:
					foIdApplication.Value = DBNull.Value; break;

				case FieldNames.Username:
					foUsername.Value = DBNull.Value; break;

				case FieldNames.Pwd:
					foPwd.Value = DBNull.Value; break;

			}
		}
		
		#endregion generic field methods
    
        #region static factories

		/// <summary>
		/// Creates a new DB object that can be added to the database as a new row
		/// </summary>
		/// <returns>The instance of the DB Object</returns>
		public static DBAppUser NewRow
		{
			get { return new DBAppUser(); }
		}

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBAppUser> ListEntity(object foIdAppUser, object foIdEntity, object foIdApplication, object foUsername, object foPwd)
		{
			DBAppUser helper = new DBAppUser();
			

			helper.foIdAppUser.Value = foIdAppUser;

			helper.foIdEntity.Value = foIdEntity;

			helper.foIdApplication.Value = foIdApplication;

			helper.foUsername.Value = foUsername;

			helper.foPwd.Value = foPwd;


			return helper.GetEntityInstancesList(helper.Fields.ToArray()).Cast<DBAppUser>();
        }

		/// <summary>
		/// Returns multiple rows from the Datasource by a given set of WHERE clause fields, only includes fields where value != null
		/// </summary>
		/// <example>List of fields to filter by, null to ignore field (null = all).</example>
		/// <returns>A collection with the filtered results. </returns>
		internal static IEnumerable<DBAppUser> ListEntity()
		{
			return new DBAppUser().GetEntityInstancesList(new DbField[0]).Cast<DBAppUser>();
        }

      		/// <summary>
		/// Returns a single row from the datasource by a given set of RUID strong-typed values
		/// </summary>
		/// <returns>The instance for this key or a new one if no match is found.</returns>
		internal static DBAppUser GetEntity(int foIdAppUser)
		{
			DBAppUser helper = new DBAppUser();

			helper.foIdAppUser.Value = foIdAppUser;

			helper = helper.GetEntityInstance(helper.Ruid) as DBAppUser;
			
			return helper;
		}


        /// <summary>
        /// Returns multiple rows from the Datasource that referentiate a specific foreign object 
        /// </summary>
        /// <param name="foIdEntity">The <see cref="DBEntity"/> object to filter by.</param>
        /// <returns>A collection with the filtered results.</returns>
        public static  IEnumerable<DBAppUser> ListEntityIdEntity(DBEntity foIdEntity)
        {
          DBAppUser helper = new DBAppUser();

          helper.foIdEntity.Value = foIdEntity.IdEntity;

          return helper.GetEntityInstancesList(helper.foIdEntity).Cast<DBAppUser>();
        }

        /// <summary>
        /// Returns multiple rows from the Datasource that referentiate a specific foreign object 
        /// </summary>
        /// <param name="foIdApplication">The <see cref="DBApplication"/> object to filter by.</param>
        /// <returns>A collection with the filtered results.</returns>
        public static  IEnumerable<DBAppUser> ListEntityIdApplication(DBApplication foIdApplication)
        {
          DBAppUser helper = new DBAppUser();

          helper.foIdApplication.Value = foIdApplication.IdApplication;

          return helper.GetEntityInstancesList(helper.foIdApplication).Cast<DBAppUser>();
        }

		#endregion static factories
	}
}